# for M&B v.903
from ID_items import *
from ID_parties import *
from ID_troops import *
from header_operations import *
from header_colors import *
##############################################################
# These constants are used in various files.
# If you need to define a value that will be used in those files,
# just define it here rather than copying it across each file, so
# that it will be easy to change it if you need to.
##############################################################
# Some internal constants
trade_goods_begin = "itm_rice"
trade_goods_end = "itm_hosokawa_intro_letter"
rice_goods_begin = 'itm_rice'
rice_goods_end = 'itm_millet'
food_begin = "itm_millet"
food_end = "itm_hemp"
morale_boosters_begin = rice_goods_begin
morale_boosters_end = food_end
horses_begin = "itm_draft_horse"
horses_end = "itm_waraji_a"
weapons_begin = "itm_tanto"
weapons_end = "itm_light_yumi"
ranged_weapons_begin = "itm_light_yumi"
ranged_weapons_end = "itm_jitte"
armors_begin = "itm_waraji_a"
armors_end = "itm_tanto"
num_trade_goods = itm_hosokawa_intro_letter - itm_hemp
num_cities = p_village_40 - p_city_1
# binary conversion constants
bit8 = 128
bit7 = 64
bit6 = 32
bit5 = 16
bit4 = 8
bit3 = 4
bit2 = 2
bit1 = 1
# object definition constants
obj_troop = -101101
obj_party = -101102
obj_party_template = -101103
obj_faction = -101104
obj_item = -101105
obj_quest = -101106
obj_agent = -101107
obj_scene = -101108
# operation definition constants
op_asn = -101200
op_add = -101201
op_sub = -101202
op_mul = -101203
op_div = -101204
op_mod = -101205
op_min = -101206
op_max = -101207

metal_weapons_begin = 'itm_tanto'
metal_weapons_end = 'itm_ko_naginata'
wooden_weapons_begin = 'itm_ko_naginata'
wooden_weapons_end = 'itm_ono'
low_quality_weapons_begin = 'itm_club1'
low_quality_weapons_end = 'itm_ya'
repairable_items_begin = 'itm_tanto'
repairable_items_end = 'itm_club1'

null = -100

# booleans
true = 1
false = 0

# party orders
orders_capture = -200001
orders_raid = -200002
orders_caravan_trade = -201001
orders_caravan_inquire = -201002
orders_caravan_deliver_goods = -201003
orders_caravan_return = -201004
orders_caravan_mutual_trade = -201005

#trade caravan spawn options
tcs_opt_no_inquiry = -201501
tcs_opt_deliver_goods = -201502

# generate trade revenue modes
gtr_trading = -202001
gtr_mutual_trading = -202002
gtr_return = -202003

# facility types
ft_farm = -203001
ft_paper_mill = -203002
ft_flour_mill = -203003
ft_lumber_mill = -203004
ft_foundry = -203005
ft_blacksmith = -203006
ft_weaver = -203007
ft_woodshop = -203008
ft_smokehouse = -203009
ft_potter = -203010
ft_iron_mine = -203011
ft_silver_mine = -203012

#moral constants
morale_bold = 3
morale_waxing = 2
morale_cautious = 1
morale_neutral = 0
morale_unsure = -1
morale_waning = -2
morale_desparate = -3

# merchant types
mt_goods = 1
mt_weapons = 2
mt_armor = 3
#mt_horses = 4
#mt_fishmonger = 5
#mt_moneylender = 6

# trading post constants and slots
tp_code_mask = 100000000
tp_time_code_mask = 10000
tp_fixed_fee_mask = 100
tp_percentage_fee_mask = 1

tp_flat_fee = -1001
tp_percentage_fee = -1002

slot_trading_post_code = 100
slot_trading_post_owner = 101
slot_trading_post_hours = 102
slot_trading_post_town = 103
slot_trading_post_revenue = 104
slot_trading_post_operator = 105

# trade destination constants and slots
td_code_mask = 100000000
td_time_code_mask = 10000
td_fixed_fee_mask = 100
td_percentage_fee_mask = 1

td_benefit_fixed_fee = 0
td_benefit_percentage = 1
td_benefit_managed = 2

slot_td_id = 100
slot_td_code = 101
slot_td_origin = 102
slot_td_dest = 103
slot_td_manager = 104

# item repair states
irs_repairable = 1
irs_irrepairable = 2
irs_indestructable = 3

# entry point script modes
ep_mode_first_entry = 0
ep_mode_within_city = 1

# town guards types
gt_outer_gate = 0
gt_inner_gate = 1
gt_shinden_gate = 2
gt_shinden_door = 3

#mission constants
mission_do_nothing = 0
mission_diplomacy = 1
mission_army_capture = 2
mission_army_patrol = 3
mission_war_party_capture = 4
mission_war_party_patrol = 5
mission_raiders_capture = 6
mission_raiders_raid = 7
mission_build_fort = 8
mission_intel = 9
mission_bandits_raid = 10
mission_bandits_capture_village = 10
mission_bandits_capture_town = 11
mission_bandits_capture_city = 12

#scene flags
scn_flag_inn = 1
scn_flag_merchant = 2
scn_flag_smithy = 3
scn_flag_manor = 4

#spawn flags (bit numbers)
spf_has_orders = 1
spf_active = 2
spf_disabled = 3
spf_warning = 4
spf_intro = 5

# sensei flags (bit numbers)
sf_mitsumaru = 1
sf_tomomoto = 2
sf_teruhisa = 3
sf_kiyouji = 4
sf_ietsuru = 5
sf_tsunetomo = 6
sf_ujiaru = 7
sf_michimori = 8
# ronin investigation quest flags
riqf_kokujin = 4
riqf_weaponsmith = 3
riqf_innkeeper = 2
riqf_merchant = 1
#class params constants
slot_class = 0
slot_rank_no = 1
slot_pay_rate = 2
slot_fp_rate = 3
slot_renown = 4
slot_title = 5
slot_wages = 6
slot_fp = 7

#array constants
array_value_null = null
array_value_length = 250
array_value_last_popped = 251
array_value_last_pushed = 252
array_value_last_queued = 253
array_value_high_index = 254
array_next_array = 255

#attributes
ca_strength = 0
ca_agility  = 1
ca_intelligence = 2
ca_charisma = 3

# skills


#character classes
class_bushi = 0
class_kuge = 1
class_merchant = 2
class_ronin = 3

# town icon states
tis_normal = 1
tis_burning = 2
tis_looted = 3
tis_deserted = 4

#p_main_party slots
slot_main_quest_origin = 0
slot_main_prisoners = 1

#other troop slots
slot_troop_intro            = 0
slot_troop_knows_name       = 1
slot_troop_gender           = 2
slot_troop_patronage        = 3
slot_troop_city             = 4
slot_troop_quest            = 5
slot_troop_quest_active     = 6
slot_troop_text             = 7
slot_troop_at_inn       = 8
slot_troop_cost = 9
slot_troop_qst_item_1       = 10
slot_troop_qst_item_2       = 11
slot_troop_qst_item_3       = 12
slot_troop_qst_item_1_count = 13
slot_troop_qst_item_2_count = 14
slot_troop_qst_item_3_count = 15
slot_troop_qst_complete     = 16
slot_troop_qst_giver        = 17
slot_troop_qst_source_party = 18
slot_troop_qst_dest_party   = 19
slot_troop_att_to_player    = 20
slot_troop_caste            = 21
slot_troop_has_joined       = 22
slot_troop_recruitable = 23
slot_troop_active = 24

#trp_player slots
slot_player_gender            = 10
slot_player_faction           = 11
slot_player_rank_array             = 12
slot_player_renown              = 13
slot_player_title             = 14
slot_player_relation_hosokawa = 15
slot_player_relation_yamana   = 16
slot_player_faction_points    = 17
slot_player_quest_giver       = 18
slot_player_goods_1           = 19
slot_player_goods_2           = 20
slot_player_goods_3           = 21
slot_player_goods_4           = 22
slot_player_lord              = 23
slot_player_castle            = 24
slot_player_town              = 25
slot_player_haruko_training_site = 26
slot_player_tsuruhiro_training_site = 27
slot_player_akikane_training_site = 28
slot_player_shinbo_training_site = 29
slot_player_rank_ptr = 30
slot_player_fp_rate = 31
slot_player_training_flags = 32

#companion slots
slot_comp_training = 40
slot_comp_training_flags = 41

#sensei_slots
slot_sensei_complete = 9
slot_sensei_comp_to_train = 10
slot_sensei_begin_kengo = 11
slot_sensei_difficulty = 12
slot_sensei_weapon_type = 13
slot_sensei_apprentice = 14
slot_sensei_flag = 21
slot_sensei_prof_oh     = 22
slot_sensei_prof_th     = 23
slot_sensei_prof_pl     = 24
slot_sensei_prof_ar     = 25
slot_sensei_prof_tr     = 26
slot_sensei_skl_ps      = 27
slot_sensei_skl_pd      = 28
slot_sensei_skl_pt      = 29
slot_sensei_skl_ath     = 30
slot_sensei_skl_wm      = 31

# weapon types
sword = 1
bladed_polearm = 2
archery = 3
blunt_polearm = 4
thrown = 5

########################################################
##  PARTY TEMPLATE SLOTS   #############################
########################################################

slot_template_composition_array = 0
slot_template_village_garrison_composition = 1
slot_template_town_garrison_composition = 2
slot_template_city_garrison_composition = 3
slot_template_spawn_cost_base = 4
slot_template_spawn_cost = 5

#Scene Slots
slot_scene_visited      = 0

#scn_item slots

slot_dojo_sensei = 1
slot_dojo_trainee = 2
slot_dojo_training = 3
slot_dojo_sensei_away = 4

#economic variables
#demand levels
dmd_very_low = -2
dmd_low = -1
dmd_normal = 0
dmd_high = 1
dmd_very_high = 2

#abundance calculation variables
#terrain types
ter_seaside = 1
ter_island = 2
ter_lakeside = 3
ter_lowland = 4
ter_highland = 5
ter_low_valley = 6
ter_high_valley = 7

#city types
ct_small_village = 100
ct_village = 500
ct_large_village = 1000
ct_town = 5000
ct_large_town = 10000
ct_city = 50000
ct_port = 50500

#faction relations
rel_enemy   = 0
rel_neutral = 1
rel_ally    = 2

#troop/party/faction attitudes
att_generous    = 3
att_friendly    = 2
att_cautious    = 1
att_secretive   = 0
att_defensive   = -1
att_offensive   = -2
att_hostile     = -3

one_handed = 0
two_handed = 1
polearms  = 2
archery = 3
crossbows = 4
throwing = 5
########################################################
##  ITEM SLOTS             #############################
########################################################

# item types
sit_metal_weapon = 1
sit_wooden_weapon = 2
sit_ranged_weapon = 3
sit_armor = 4



slot_item_is_checked              = 0
slot_item_food_bonus              = 1
slot_item_seaside = 2
slot_item_island = 3
slot_item_lakeside = 4
slot_item_lowland = 5
slot_item_highland = 6
slot_item_low_valley = 7
slot_item_high_valley = 8
slot_item_small_village = 9
slot_item_village = 10
slot_item_large_village = 11
slot_item_town = 12
slot_item_large_town = 13
slot_item_city = 14
slot_item_port = 15
slot_item_jan = 16
slot_item_feb = 17
slot_item_mar = 18
slot_item_apr = 19
slot_item_may = 20
slot_item_jun = 21
slot_item_jul = 22
slot_item_aug = 23
slot_item_sep = 24
slot_item_oct = 25
slot_item_nov = 26
slot_item_dec = 27
slot_item_winter_demand = 30
slot_item_spring_demand = 31
slot_item_summer_demand = 32
slot_item_autumn_demand = 33
slot_item_war_demand = 34
slot_item_durability = 35
slot_item_repair_state = 36
slot_item_repair_chance = 37
slot_item_type = 38
slot_item_demand_coefficient = 39
slot_item_abundance_start = 100 
slot_item_prices_start = slot_item_abundance_start + num_cities + 1
slot_item_demand_start = slot_item_prices_start + num_cities + 1
slot_item_production_start = slot_item_demand_start + num_cities + 1

########################################################
##  AGENT SLOTS            #############################
########################################################

slot_agent_target_entry_point     = 0
slot_agent_target_x_pos           = 1
slot_agent_target_y_pos           = 2
slot_agent_x_pos                  = 3
slot_agent_y_pos                  = 4
slot_agent_z_pos                  = 5
slot_agent_is_not_reinforcement   = 6
slot_agent_hit_points             = 7
slot_agent_morale                 = 8
slot_agent_map_overlay_id         = 10
slot_agent_warning_overlay_id     = 11

########################################################
##  FACTION SLOTS          #############################
########################################################

slot_faction_hosokawa_ally    = 0
slot_faction_yamana_ally      = 1
slot_faction_player_fame      = 2
slot_faction_att_to_player    = 3
slot_faction_strength         = 4
slot_faction_morale           = 5
slot_faction_spawn_points     = 6
slot_faction_intel            = 7
slot_faction_possession_flags = 8
slot_faction_treasury         = 9

slot_faction_ai_state             = 10
slot_faction_ai_object            = 11

slot_faction_leader               = 20
slot_faction_vassal_of            = 21

slot_faction_quest = 30
slot_faction_letter = 31
slot_faction_enemy_faction = 32
slot_faction_joined = 33

slot_faction_tier_1_troop         = 41
slot_faction_tier_2_troop         = 42
slot_faction_tier_3_troop         = 43
slot_faction_tier_4_troop         = 44
slot_faction_tier_5_troop         = 45

slot_faction_city_possession_flags = 50
slot_faction_town_possession_flags = 51
slot_faction_village_possession_flags_1 = 52
slot_faction_village_possession_flags_2 = 53

slot_faction_reinforcements_a        = 70
slot_faction_reinforcements_b        = 71
slot_faction_reinforcements_c        = 72
slot_faction_reinforcements_d        = 73

slot_faction_num_armies              = 80
slot_faction_num_castles             = 81
slot_faction_num_towns               = 82



########################################################
##  PARTY SLOTS            #############################
########################################################

# Slots 0 - 9 are common to all parties and are reserved!!!
slot_party_type = 0  #spt_caravan, spt_town, spt_castle
slot_party_food = 1
slot_party_icon = 2
slot_party_icon_state = 3
slot_party_gold = 4
slot_party_retreat_flag        = 5
slot_party_ignore_player_until = 6
slot_party_ai_state            = 7
slot_party_ai_object           = 8
slot_party_commander_party = 9 # default -1

#slot_party_type values
spt_city            = 1
spt_castle             = 2
spt_town               = 3
spt_village            = 4
spt_forager            = 5
spt_army          = 6
spt_patrol             = 7
spt_messenger          = 8
spt_raider             = 9
spt_scout              = 10
spt_kingdom_caravan    = 11
spt_merchant    = 11
spt_prisoner_train     = 12
spt_kingdom_hero_party = 13
##spt_merchant_caravan   = 14
spt_village_farmer     = 15
spt_ship               = 16
spt_traveler = 17
spt_deserter           = 20

#slot_party_ai_state values
spai_undefined                  = -1
spai_besieging_center           = 1
spai_traveling_to_center       = 2
spai_patroling = 3
spai_patrolling_around_center   = 4
spai_raiding_around_center      = 5
spai_raiding_village            = 6
spai_holding_center             = 7
spai_helping_town_against_siege = 9
spai_engaging_army              = 10
spai_accompanying_army          = 11
spai_trading_with_town          = 13
spai_retreating_to_center       = 14
spai_trading_within_kingdom     = 15

#slot_town_state values
sts_normal                      = 0
sts_being_raided                = 1
sts_looted                      = 2
sts_recovering                  = 3
sts_deserted                    = 4
sts_under_siege                 = 5

slot_town_belongs_to_kingdom = 6
slot_town_lord               = 7
#slot_town_seneschal          = 8
slot_town_claimed_by_player  = 9

#army slots
slot_army_size = 10
slot_army_base = 11

#spawn slots
slot_spawn_type = slot_party_type  #spt_caravan, spt_town, spt_castle
slot_spawn_retreat_flag = slot_party_retreat_flag
slot_spawn_ignore_player_until = slot_party_ignore_player_until
slot_spawn_ai_state = slot_party_ai_state
slot_spawn_ai_object = slot_party_ai_object
slot_spawn_icon = slot_party_icon
slot_spawn_icon_state = slot_party_icon_state
slot_spawn_food = slot_party_food
slot_spawn_gold = slot_party_gold
slot_spawn_commander_party = slot_party_commander_party
slot_spawn_ID       = 10
slot_spawn_size     = 11
slot_spawn_faction  = 12
slot_spawn_active   = 13
slot_spawn_dest     = 14
slot_spawn_origin   = 15
slot_spawn_att_to_player = 16
slot_spawn_warning = 17
slot_spawn_bhvr_array = 18
slot_spawn_intro = 19
slot_spawn_array = 20
slot_spawn_td_obj = 21
slot_spawn_delay = 22
slot_spawn_orders = 23
slot_spawn_has_orders = 24
slot_spawn_caravan_demand_array = 25
slot_spawn_caravan_inv_array = 26
slot_spawn_caravan_distance = 27


#town slots
slot_town_terrain       = 10
slot_town_size          = 11
slot_town_patrol        = 12
slot_town_patrol_active = 13
slot_town_trader        = 14
slot_town_trader_active = 15
slot_town_player_relation   = 16
slot_town_att_to_player = 17
slot_town_dojo          = 18
slot_town_sensei = 19
slot_town_center        = 20
slot_town_castle        = 21
slot_town_inn           = 22
slot_town_store         = 23
slot_town_gate          = 24
slot_town_smithy        = 25
slot_town_innkeeper     = 26
slot_town_weaponsmith   = 27
slot_town_armorer       = 28
slot_town_merchant      = 29
slot_town_kokujin       = 30
slot_town_shugo         = 31
slot_town_trade_hub     = 32
slot_town_trade_dest    = 33
slot_town_trade_month   = 34
slot_town_mercs         = 35
# slot_town_mercs_2       = 36
# slot_town_mercs_3       = 37
slot_town_export_good   = 38
slot_town_export_rate   = 39
slot_town_export_good_2 = 40
slot_town_export_rate_2 = 41
slot_town_import_good   = 42
slot_town_import_rate   = 43
slot_town_import_good_2 = 44
slot_town_import_rate_2 = 45
slot_town_import_demand = 46
slot_town_export_demand = 47
slot_town_demand = 48
slot_town_treasury = slot_party_gold
slot_town_tax_rate = 51
slot_town_unrest = 52
slot_town_dest_array = 53
slot_town_initial_faction = 54
slot_town_caravan_dest_1 = 60
slot_town_caravan_dest_2 = 61
slot_town_caravan_dest_3 = 62
slot_town_garrison_source = 63
slot_town_siege_active = 64
slot_town_under_siege = 65
slot_town_siege_attacker = 66
slot_town_scene_flags = 67
slot_town_spawn_points = 68
slot_town_accumulated_rents = 70
slot_town_accumulated_tariffs = 71
slot_town_food_stores = slot_party_food
slot_town_is_besieged_by = 73
slot_town_current_improvement   = 74
slot_town_improvement_end_hour  = 75
slot_town_housing_level         = 76
slot_town_irrigation_level      = 77
slot_town_mill_level            = 78
slot_town_raided_by        = 79
slot_town_state            = 80 #svs_normal, svs_being_raided, svs_looted, svs_recovering, svs_deserted
slot_town_raid_progress    = 81
slot_town_recover_progress = 82
slot_town_smoke_added      = 83
slot_town_production_bonus = 84
slot_town_prefecture_array = 85
slot_town_shoen = 86
slot_town_broker = 87
slot_town_fishmonger = 88
slot_town_horse_trader = 89
slot_town_moneychanger = 90
slot_town_population = 91
slot_town_population_max = 92
slot_town_population_growth_factor = 93
slot_town_reinforcements_a = 95
slot_town_reinforcements_b = 96
slot_town_reinforcements_c = 97
slot_town_capital = 98
#slot_town_type                = 100  #spt_caravan, spt_town, spt_castle
slot_town_siege_days = 107
slot_town_reserve_patrol = 108
slot_town_storehouse_array = 109
slot_town_demand_array = 110
slot_town_surplus_array = 111
slot_town_facility_array = 112
slot_town_trade_good_productions_array       = 120
slot_town_trade_good_temp_productions_array  = 121
slot_town_trade_good_price_array            = 122
slot_town_trade_good_abundance_array            = 123

# fort/castle slots
slot_castle_treasury = 11
slot_castle_progress = 12
slot_castle_banner = 13
slot_castle_siege_active = 14
slot_castle_commander = 15
slot_castle_patrol = 16
slot_castle_patrol_active = 17
slot_castle_patrol_origin = 18
slot_castle_patrol_target = 19
slot_castle_patrol_orders = 20
slot_castle_exterior    = 21
slot_castle_interior    = 22
slot_castle_food_store = 50 #used for sieges
slot_castle_is_besieged_by = 51

# garrison slots
slot_garrison_cost_array = 0

# facility slots
slot_facility_town = 10
slot_facility_owner = 11
slot_facility_inputs_array = 12
slot_facility_outputs_array = 13
slot_facility_type = 14
slot_facility_name = 15
slot_facility_town = 10

#Native slot constants
slot_center_player_relation = 26

slot_center_siege_with_belfry = 27
slot_center_last_taken_by_troop = 28

# party will follow this party if set:
slot_party_commander_party = 130 #default -1

 #used for sieges
slot_center_last_spotted_enemy  = 155

#slot_castle_exterior    = 10

slot_town_arena_melee_mission_tpl = 178
slot_town_arena_torny_mission_tpl = 179
slot_town_arena_melee_1_num_teams = 180
slot_town_arena_melee_1_team_size = 181
slot_town_arena_melee_2_num_teams = 182
slot_town_arena_melee_2_team_size = 183
slot_town_arena_melee_3_num_teams = 184
slot_town_arena_melee_3_team_size = 185
slot_town_arena_melee_cur_tier    = 186
slot_town_arena_template	  = 187

slot_center_mercenary_troop_type  = 190
slot_center_mercenary_troop_amount= 191
slot_center_volunteer_troop_type  = 192
slot_center_volunteer_troop_amount= 193

slot_center_companion_candidate   = 194
slot_center_ransom_broker         = 195
slot_center_tavern_traveler       = 196
slot_center_traveler_info_faction = 197
slot_center_tavern_minstrel       = 198

slot_town_siege_days              = 200

num_party_loot_slots    = 5
slot_party_next_looted_item_slot  = 209
slot_party_looted_item_1          = 210
slot_party_looted_item_2          = 211
slot_party_looted_item_3          = 212
slot_party_looted_item_4          = 213
slot_party_looted_item_5          = 214
slot_party_looted_item_1_modifier = 215
slot_party_looted_item_2_modifier = 216
slot_party_looted_item_3_modifier = 217
slot_party_looted_item_4_modifier = 218
slot_party_looted_item_5_modifier = 219

slot_village_bound_center         = 220
slot_village_market_town          = 221
slot_village_farmer_party         = 222
slot_party_home_center            = 223



num_trade_goods = itm_string_of_coins - itm_rice
slot_town_trade_good_productions_begin       = 240
slot_town_trade_good_temp_productions_begin  = slot_town_trade_good_productions_begin + num_trade_goods + 1
slot_town_trade_good_prices_begin            = slot_town_trade_good_temp_productions_begin + num_trade_goods + 1

kingdom_party_types_begin = spt_forager
kingdom_party_types_end = spt_kingdom_hero_party + 1

# constants
shoen_buy_shares = 0
shoen_sell_shares = 1
# party slots
slot_offset = 0
slot_shoen_town = slot_offset + 1
slot_shoen_broker = slot_offset + 2
slot_shoen_size = slot_offset + 3
slot_shoen_labor = slot_offset + 4
slot_shoen_treasury = slot_offset + 5
slot_shoen_total_shares = slot_offset + 6
slot_shoen_outstanding_shares = slot_offset + 7
slot_shoen_share_price = slot_offset + 8
slot_shoen_capitalization = slot_offset + 9
slot_shoen_dividend = slot_offset + 10
slot_shoen_production = slot_offset + 11
slot_shoen_production_price = slot_offset + 12
slot_shoen_improvement_level = slot_offset + 13
slot_shoen_time_since_last_improvement = slot_offset + 14
slot_shoen_time_since_last_transaction = slot_offset + 15
slot_shoen_labor_moving_avg = slot_offset + 16
slot_shoen_share_price_moving_avg = slot_offset + 17

num_shareholders = trp_city_1_kokujin - trp_hosokawa_katsumoto + 1

slot_shoen_shareholders_array = slot_offset + 20
slot_shoen_shareholders_shares_owned_array = slot_offset + 21
slot_shoen_shareholders_accumulated_dividends_array = slot_offset + 22
slot_shoen_shareholders_dca_value_array = slot_offset + 23
slot_shoen_shareholders_total_capitalization_array = slot_offset + 24

slot_tp_name = 10
slot_tp_owner = 11
slot_tp_fee_code = 12

# broker talk modes
broker_talk_mode_no_investments = -101
broker_talk_mode_investments_available = -102

#slot_faction_ai_state values
sfai_undefined                 = -1
sfai_default                   = 0
sfai_attacking_center          = 1

#$g_player_icon_state values
pis_normal                      = 0
pis_camping                     = 1
pis_ship                        = 2


########################################################
##  SCENE SLOTS            #############################
########################################################
slot_scene_visited              = 0
slot_scene_belfry_props_begin   = 10


########################################################
##  TROOP SLOTS            #############################
########################################################
#slot_troop_role         = 0  # 10=Kingdom Lord

slot_troop_occupation          = 2  # 0 = free, 1 = merchant
#slot_troop_duty               = 3  # Kingdom duty, 0 = free
slot_troop_state               = 3  
slot_troop_last_talk_time      = 4
slot_troop_met                 = 5
slot_troop_party_template      = 6
#slot_troop_kingdom_rank        = 7

slot_troop_renown              = 7

slot_troop_is_prisoner         = 8  # important for heroes only
#slot_troop_is_player_companion = 9  # important for heroes only:::USE  slot_troop_occupation = slto_player_companion

slot_troop_leaded_party        = 10 # important for kingdom heroes only
slot_troop_wealth              = 11 # important for kingdom heroes only
slot_troop_cur_center          = 12 # important for royal family members only (non-kingdom heroes)

slot_troop_banner_scene_prop   = 13 # important for kingdom heroes and player only

slot_troop_does_not_give_quest = 20
slot_troop_player_debt         = 21
slot_troop_player_relation     = 22
slot_troop_player_favor        = 23
slot_troop_last_quest          = 24
slot_troop_last_quest_betrayed = 25

slot_troop_spouse              = 30
slot_troop_father              = 31
slot_troop_mother              = 32
slot_troop_daughter            = 33
slot_troop_son                 = 34
slot_troop_sibling             = 35
slot_troop_lover               = 36

slot_troop_enemy_1             = 40
slot_troop_enemy_2             = 41
slot_troop_enemy_3             = 42
slot_troop_enemy_4             = 43
slot_troop_enemy_5             = 44

slot_troop_enemies_begin       = 40
slot_troop_enemies_end         = 45

slot_troop_family_begin       = 30
slot_troop_family_end         = 36

slot_troop_honorable          = 50
#slot_troop_merciful          = 51

#Encounter types
enctype_fighting_against_village_raid = 1
enctype_catched_during_village_raid   = 2


### Troop occupations slot_troop_occupation
##slto_merchant           = 1
slto_kingdom_hero       = 2
slto_player_companion   = 3
slto_kingdom_lady       = 4
slto_kingdom_seneschal  = 5
slto_robber_knight      = 6

stl_unassigned          = -1
stl_reserved_for_player = -2
stl_rejected_by_player  = -3


########################################################
##  QUEST SLOTS            #############################
########################################################

slot_quest_giver = 0
slot_quest_source_party = 1
slot_quest_target_party = 2
slot_quest_target_troop = 3
slot_quest_active = 4
slot_quest_xp_reward = 5
slot_quest_gold_reward = 6
slot_quest_next_quest = 7
slot_quest_active = 8
slot_quest_target_party_2 = 9
slot_quest_item_1 = 10
slot_quest_item_2 = 11
slot_quest_item_3 = 12
slot_quest_item_4 = 13
slot_quest_item_5 = 14
slot_quest_item_1_cnt = 15
slot_quest_item_2_cnt = 16
slot_quest_item_3_cnt = 17
slot_quest_item_4_cnt = 18
slot_quest_item_5_cnt = 19
slot_quest_item_1_imod = 20
slot_quest_item_2_imod = 21
slot_quest_item_3_imod = 22
slot_quest_item_4_imod = 23
slot_quest_item_5_imod = 24
slot_quest_item_1_value = 25
slot_quest_item_2_value = 26
slot_quest_item_3_value = 27
slot_quest_item_4_value = 28
slot_quest_item_5_value = 29
slot_quest_troop_1 = 30
slot_quest_troop_2 = 31
slot_quest_troop_3 = 32
slot_quest_troop_1_cnt = 33
slot_quest_troop_2_cnt = 34
slot_quest_troop_3_cnt = 35
slot_quest_shugo_dialog = 36
slot_quest_flags = 37
slot_quest_complete = 38
slot_quest_companion_training_dojo = 40
slot_quest_companion_training_sensei = 41
slot_quest_companion_training_companion = 42
slot_quest_pt_count = 43
slot_quest_pt_defeated = 44
slot_quest_target_party_template    = 45
slot_quest_timed = 46
slot_quest_time_to_completion = 47
slot_quest_party_1 = 50
slot_quest_party_2 = 51
slot_quest_party_3 = 52
slot_quest_party_4 = 53
slot_quest_party_5 = 54
slot_quest_end = 60

slot_quest_faction_joined = 10
slot_quest_faction_pay_rate = 11

slot_quest_class_pay = 101
slot_quest_class_fp = 102
slot_quest_class_pay_rate = 103
slot_quest_class_fp_rate = 104

slot_quest_za_faction_item = 70
slot_quest_za_master = 71
slot_quest_za_player_standing = 72
slot_quest_za_faction = 73

# quest states
# qst_flags_mask = 10000
# qst_inactive = 0
# qst_active = 1
# qst_complete = 10
# qst_succeed = 100
# qst_failed = 1000



########################################################
rel_enemy   = 0
rel_neutral = 1
rel_ally    = 2


#Talk contexts
tc_town_talk                  = 0
tc_party_encounter            = 1
tc_lord_talk_in_center        = 2
tc_siege_commander            = 3
tc_join_battle_ally           = 4
tc_join_battle_enemy          = 5
tc_castle_commander           = 6
tc_hero_freed                 = 7
tc_hero_defeated              = 8
tc_entering_center_quest_talk = 9
tc_back_alley                 = 10
tc_siege_won_seneschal        = 11
tc_ally_thanks                = 12
tc_tavern_talk                = 13
tc_quest_succeeded = 14
tc_quest_failed = 15
tc_no_investments = 16
tc_investments_available = 17
# daimyo/shugo talk contexts
tc_daimyo_shugo_assigned = -105001
tc_daimyo_faction_invite = -105002
tc_daimyo_join_faction = -105003
tc_daimyo_invite_quest_active = -105004
tc_daimyo_ronin_choice = -105005
tc_daimyo_merchant = -105006
tc_mc_mon_to_string = -105100
tc_mc_mon_to_koban = -105101
tc_mc_string_to_mon = -105102
tc_mc_koban_to_mon = -105103
tc_mc_koban_stack_to_mon = -105104
tc_mc_koban_stack_to_koban = -105105
tc_mc_koban_to_koban_stack = -105106
tc_mc_base = -105100
tc_shugo_quest_succeeded = -105200
tc_shugo_quest_failed = -105201
tc_shugo_quest_concluded = -105202
tc_shugo_quest_proceed = -105203
# spawn encounter talk contexts
tc_spawn_enc_neutral = -101001
tc_spawn_enc_favorable = -101002
tc_spawn_enc_unfavorable = -101003
# dialog states
ds_end = -104001
ds_fight = -104002
ds_alert = -104003
ds_flee = -104004
ds_friendly = 100
ds_neutral = 101
ds_combative = 102
ds_cowardly = 103

# quest talk contexts
tc_merchant_deliver_shipment = -102001

reinforcement_cost            = 400

merchant_toll_duration        = 72 #Tolls are valid for 72 hours

hero_escape_after_defeat_chance = 80 #TODO: it should be:80
#main_factions_begin = "fac_swadians"
#main_factions_end   = "fac_khergits"

factions_begin = 'fac_hosokawa'
factions_end = 'fac_end_factions'

raid_distance = 4

items_begin = "itm_wheat"
items_end   = "itm_draft_horse"

all_towns_begin = "p_city_1"
all_towns_end   = "p_temple_1"

centers_begin = all_towns_begin
centers_end   = all_towns_end

cities_begin = "p_city_1"
cities_end   = "p_town_1"

towns_begin = "p_town_1"
towns_end   = "p_village_1"

villages_begin = "p_village_1"
villages_midpoint = 'p_village_21'
villages_end   = "p_temple_1"

temples_begin = "p_temple_1"
temples_end   = "p_bandit_camp"

castles_begin = 0
castles_end = 1

bushi_begin = 'trp_hosokawa_katsumoto'
bushi_end = 'trp_city_1_kokujin'

spawn_points_begin = "p_city_1"
spawn_points_end = "p_spawn_points_end"

hosokawa_shugo_begin = "trp_takase_shugo"
hosokawa_shugo_end   = "trp_hidaka_shugo"

yamana_shugo_begin = "trp_hidaka_shugo"
yamana_shugo_end   = "trp_city_5_kokujin"

kokujin_begin = "trp_city_5_kokujin"
kokujin_end   = "trp_city_1_innkeeper"

innkeepers_begin    = "trp_city_1_innkeeper"
innkeepers_end      = "trp_city_1_armorer"

merchants_begin  = "trp_city_1_merchant"
merchants_end    = "trp_city_1_fishmonger"

fishmongers_begin = 'trp_city_1_fishmonger'
fishmongers_end = 'trp_broker_1'

shoen_brokers_begin = 'trp_broker_1'
shoen_brokers_end = 'trp_moneychanger_1'

moneychangers_begin = 'trp_moneychanger_1'
moneychangers_end = 'trp_town_walker_1'

armorers_begin  = "trp_city_1_armorer"
armorers_end    = "trp_city_1_weaponsmith"

weaponsmiths_begin = "trp_city_1_weaponsmith"
weaponsmiths_end   = "trp_city_1_merchant"

dojo_masters_begin = "trp_mitsumaru"
dojo_masters_end   = "trp_temple_1_priest"

souhei_begin = 'trp_monk_t'
souhei_end = 'trp_ikko_peasant'

shinobi_begin = 'trp_shinobi_apprentice'
shinobi_end = 'trp_last_troop'

npc_lords_begin = 'trp_hosokawa_katsumoto'
npc_lords_end = 'trp_city_1_kokujin'

heroes_begin = "trp_haruko"
heroes_end   = "trp_end_troops"

town_walkers_begin = 'trp_town_walker_1'
town_walkers_end = 'trp_town_walker_end'

outfit_troops_begin = trp_samurai
outfit_troops_end = trp_armed_peasant + 1

outfitters_begin = 'trp_kingmaker'
outfitters_end = 'trp_kingmaker'

#quest constants
bushi_storyline_quests_begin = 'qst_storyline_bushi_rebellion'
bushi_storyline_quests_end = 'qst_bushi_suppress_rebels'
bushi_random_quests_begin = 'qst_bushi_suppress_rebels'
bushi_random_quests_end = 'qst_end_quests'
kuge_storyline_quests_begin = 'qst_storyline_bushi_rebellion'
kuge_storyline_quests_end = 'qst_kuge_emissary'
kuge_random_quests_begin = 'qst_kuge_emissary'
kuge_random_quests_end = 'qst_storyline_bushi_rebellion'
ronin_storyline_quests_begin = 'qst_ronin_storyline_capture_bandit_leader'
ronin_storyline_quests_end = 'qst_ronin_defeat_bandit_parties'
ronin_random_quests_begin = 'qst_ronin_defeat_bandit_parties'
ronin_random_quests_end = 'qst_merchant_storyline_establish_trading_post'
merchant_storyline_quests_begin = 'qst_merchant_storyline_establish_trading_post'
merchant_storyline_quests_end = 'qst_merchant_storyline_secure_supplier'
merchant_random_quests_begin = 'qst_merchant_establish_trading_post'
merchant_random_quests_end = 'qst_monk_escort_pilgrims'

average_price_factor = 1000
minimum_price_factor = 100
maximum_price_factor = 10000

#TODO: Change these when items are ordered


# Some constants for merchant invenotries
merchant_inventory_space = 30
num_merchandise_goods = 40

num_max_river_pirates = 25
num_max_zendar_peasants = 25
num_max_zendar_manhunters = 10

num_max_dp_bandits = 10
num_max_refugees = 10
num_max_deserters = 10

num_max_militia_bands = 15
num_max_armed_bands = 12

num_max_vaegir_punishing_parties = 20
num_max_rebel_peasants = 25

num_max_frightened_farmers = 50
num_max_undead_messengers  = 20

num_forest_bandit_spawn_points = 1
num_mountain_bandit_spawn_points = 1
num_steppe_bandit_spawn_points = 1
num_black_khergit_spawn_points = 1
num_sea_raider_spawn_points = 2

peak_prisoner_trains = 4
peak_kingdom_caravans = 12
peak_kingdom_messengers = 3


# Note positions
note_troop_location = 3

#battle tactics
btactic_hold = 1
btactic_follow_leader = 2
btactic_charge = 3
btactic_stand_ground = 4

#default right mouse menu orders
cmenu_move = -7

#misc
player_party = 'p_main_party'
#cities

south_kyoto = "p_city_1"
west_kyoto = "p_city_2"
north_kyoto = "p_city_3"
east_kyoto = "p_city_4"
hyogo = "p_city_5"
himeji = "p_city_6"
obama = "p_city_7"
kakogawa = "p_city_8"
otsu = "p_city_9"
sakai = "p_city_10"
wakayama = "p_city_11"
nara = "p_city_12"
fujidera = "p_city_13"
tsuruga = "p_city_14"
takase = "p_town_1"
akashi = "p_town_2"
uji = "p_town_3"
kameyama = "p_town_4"
aioi = "p_town_5"
takashima = "p_town_6"
yodo = "p_town_7"
ono = "p_town_8"
kishiwada = "p_town_9"
sumoto = "p_town_10"
sasayama = "p_town_11"
hashimoto = "p_town_12"
fukuchiyama = "p_town_13"
ueno = "p_town_14"
takada = "p_town_15"
moriyama = "p_town_16"
shiotsu = "p_town_17"
hikone = "p_town_18"
miyazu = "p_town_19"
hidaka = "p_town_20"
itami = "p_village_1"
sanda = "p_village_2"
misaki = "p_village_3"
haga = "p_village_4"
takahama = "p_village_5"
nose = "p_village_6"
nishiwaki = "p_village_7"
okawachi = "p_village_8"
yamasaki = "p_village_9"
ikuno = "p_village_10"
iwaji = "p_village_11"
imazu = "p_village_12"
hiyoshi = "p_village_13"
mikata = "p_village_14"
miyama = "p_village_15"
naga = "p_village_16"
izushi = "p_village_17"
kasumi = "p_village_18"
oya = "p_village_19"
muraoka = "p_village_20"
kinosaki = "p_village_21"
utano = "p_village_22"
hikami = "p_village_23"
kizu = "p_village_24"
azuchi = "p_village_25"
nagahama = "p_village_26"
sekigahara = "p_village_27"
amino = "p_village_28"
santo = "p_village_29"
oe = "p_village_30"
maizuru = "p_village_31"
ine = "p_village_32"
nabari = "p_village_33"
nishiyoshino = "p_village_34"
nagano = "p_village_35"
kawakami = "p_village_36"
mitsue = "p_village_37"
iga = "p_village_38"
hino = "p_village_39"
shigaraki = "p_village_40"
enryaku_ji = "p_temple_1"

# custom operations

try_for_towns = (try_for_range,':town',hyogo,villages_end)
sanity_check = (display_message,'@Sanity check',debug_text)



# battle mini map constants

green1                       = 0x388B36
green2                       = 0x387836
green3                       = 0x386036
green4                       = 0x385136
green5                       = 0x384836
brown1                       = 0x4B4836
brown2                       = 0x604836
brown3                       = 0x563D2C
brown4                       = 0x4E3725
brown5                       = 0x472C1A
brown6                       = 0x3C2314
brown7                       = 0x301E0B
brown8                       = 0x261505
black                        = 0x000000
blue1                        = 0x007777
blue2                        = 0x005577
blue3                        = 0x003377
dark_red                     = 0x990011
